{extend name="layout:base" /}

{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="tbList" class="layui-table" lay-filter="tbList" ></table>
            <script type="text/html" id="state">
                <input type="checkbox" name="state" value="{{d.id}}" lay-skin="switch" lay-text="正常|停用" lay-filter="state" {{ d.state== 1 ? 'checked' : '' }}
                {if condition="$Think.session.admin.levelNum <10 "}disabled{/if} >
            </script>
            <script type="text/html" id="typeid">
                {{#  if(d.state ==0){ }}<span class="layui-btn layui-btn-xs ">审核中</span>{{#  } }}
                {{#  if(d.state ==1){ }}<span style="color:#ff0000">审核通过</span>{{#  } }}
                {{#  if(d.state ==2){ }}<span >已转账</span>{{#  } }}
            </script>

            <script type="text/html" id="op">
                {if condition="$Think.session.admin.levelNum ==50 or ($Think.session.admin.levelNum>1 and $Think.session.admin.departid==2) "}
                <a class="layui-btn layui-btn-xs " lay-event="del_money" >删除并返还金额</a>
                {/if}
            </script>
        </div>
    </div>
</div>

{/block}

{block name="script"}
<script>
    layui.config({
        base: '__STATIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'util','form'], function () {

        //表格
        var $ = layui.$,form = layui.form,layer = layui.layer,table = layui.table;
        table.render({
            elem: '#tbList',
            url: "{:url('getApplyList')}",
            toolbar: '#toolbarDemo',
            totalRow: true,
            cellMinWidth: 80,
            cols: [[
                {type: 'checkbox', fixed: 'left'},
                {field: 'id', fixed: 'left', title: 'ID',width:66},
                {field: 'seoname',fixed: 'left',title: '优化师'},
                {field: 'money',  title: '提现金额'},
                {field: 'seoMoney',  title: '账户余额'},
                {field: 'intime',  title: '申请时间'},
                {field: 'state',title: '状态', templet:'#typeid'},
                {fixed: 'right', title: '操作',width:200, toolbar: '#op'}
            ]],
            page: true,
            limit:15
        });


        // 监听工具条
        table.on('tool(tbList)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del_money') {
                layer.confirm('确定删除并返还该关键词？', {icon: 3, title: '提示'}, function (index) {
                    $.post("{:url('del_money')}", {id: data['id']}, function (result) {
                        if (result['code'] == 0) {
                            layer.msg(result['msg'], {icon: 1, time: 2000}, function () {
                                location.reload();
                            });
                        } else {
                            layer.msg(result['msg'], {icon: 3, time: 3000});
                        }
                    });
                });
            }
        });

        $('#keyKf').click(function () {
            var url = "{:url('keyKf')}?keyID=" + kid;
            var index = layer.open({
                type: 2,
                title: '关键词扣费',
                area: ['90%', '90%'],
                shade: 0,
                maxmin: true,
                content: url,
                zIndex: layer.zIndex
            });
        });

        //监听推荐
        form.on('switch(state)', function (data) {
            //停用
            var id=data.value;
            layer.open({
                content: '确认修改该关键词状态?'
                ,btn: ['确定', '取消']
                ,yes: function(index, layero){
                    $.post("{:url('set_state')}",{id:id,'state': data.elem.checked ? 1 : 3}, function (result) {
                        if (result['code'] == 0) {
                            location.reload();
                        } else {
                            layer.msg(result['msg'], {icon: 3, time: 3000});
                        }
                    });
                    form.render();
                    layer.close(index);
                }
                ,btn2: function(index, layero){
                    layer.close(index);
                }
            });
            return false;



        });


        //操作
        var $ = layui.$, active = {
            add: function (obj) {
                var index = layer.open({
                    type: 2,
                    title: '添加站点',
                    area: ['90%', '90%'],
                    shade: 0,
                    maxmin: true,
                    content: "{:url('add')}?webID="+wid,
                    zIndex: layer.zIndex
                });
                // layer.full(index);
            },
            reload: function(){
                var order=$('#order').val();
                var pid=$('#pid').val();
                var cid=$('#cid').val();
                var keywords=$('#keywords').val();

                //执行重载
                table.reload('tbList', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        pid: pid
                        ,cid: cid
                        ,order: order
                        ,keywords: keywords
                    }
                });

            }
        };

        // $("#btnAdd").on('click', function () {
        //     var type = $(this).data('type');
        //     active[type] ? active[type].call(this) : '';
        // });

        $('.test-table-reload-btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });

</script>
{/block}